#include<graphics.h>
#include<stdio.h>
#include <conio.h>

void main()
{
	float  vy, g, vx, rectLeftX, rectHeight, width, rectwidth;
	float R, ballX, ballY, height, isTouchdown;
#pragma region ֵ
	height = 400;
	width = 600;
	ballX = 100;
	R = 20;
	g = 0.3;
	vy = 0;
	rectwidth = 30;
	rectLeftX = width * 3 / 4;
	rectHeight = 100;
	vx = -3;

	int score = 0;
	ballY = height - R;
#pragma endregion	
	initgraph(width, height);
	while (1)
	{
		cleardevice();
		if (ballY >= height - R) {
			ballY = height - R;
		}
		fillcircle(ballX, ballY, R);
		fillrectangle(rectLeftX, height - rectHeight, rectLeftX + rectwidth, height);
		if (_kbhit()) {
			char i = _getch();
			if (i == ' ' && ballY == height - R)
			{
				vy = -13;
			}
		}
		rectLeftX += vx;
		if (rectLeftX <= 0)
		{
			score = score + 1;
			rectLeftX = width;
			rectHeight = rand() % int(height / 4) + height / 4;
			vx = rand() / float(RAND_MAX) * 4 - 7;
		}
		if (rectLeftX < ballX + R
			&& height - rectHeight<ballY + R
			&& rectLeftX + rectwidth > ballX - R)
		{
			score = 0;
			Sleep(100);

    printf("hao!");
}